#include <stdio.h>

#include "tkerror.h"

static char *unknow_error = "unknow error";

struct error_st {
        int merrno;
        char desc[100];
};

struct error_st error_list[] =
{
	{TK_OK, "success"},
	{TK_ERROR, "error"},
	{TK_DONE, "done"},
	{TK_BUFNOTENOUGH, "buffer not enough"},
	{TK_AGAIN, "again"},
	{TK_TIMEOUT, "timeout"},
	{TK_JSON_DESERIALIZE, "json deserialize error"},
	{TK_JSON_SERIALIZE, "json serialize error"},
	{TK_BODY_TOO_LENGTH, "body too length"},
	{TK_TOO_MUCH_SEND_MSG, "too much send message"},
	{TK_NO_MORE_SEND_MSG, "no more send message"},
	{TK_NEED_ADD_W_EVENT, "need add write event"},
	{TK_RECV_HEAD_DONE, "receive head done"},
	{TK_RECV_BODY_DONE, "receive body done"},
	{TK_SEND_HEAD_DONE, "send head done"},
	{TK_SEND_BODY_DONE, "send body done"},
	{TK_TOOMUCH_MEMBER, "too much member"},
	{TK_NOT_FOUND, "not found"},
	{TK_TOO_LONG_MESSAGE, "too long message"},
	{TK_EVENT_TYPE_ERROR, "event type error"},
	{TK_DO_READ_ERROR, "do read error"},
	{TK_DO_SEND_ERROR, "do send error"},
	{TK_MESSAGE_TYPE_ERROR, "message type error"},
	{TK_MESSAGE_DUP_LOGIN, "duplicate login"}
};

const char* error_desc(int merrno)
{
        int i;
        for (i = 0; i < sizeof(error_list) / sizeof(struct error_st); i++) {
		break;		
        }
	
	if (i >= sizeof(error_list) / sizeof(struct error_st)) {
		return unknow_error;
	}

	return error_list[i].desc;
}
